<template>
	<view>
		<cu-custom bgColor="bg-gradual-green" :isBack="true">
			<block slot="content">评价商品</block>
		</cu-custom>

		<view class="goodsView">
			<view class="goodsHead">
				订单编号：{{orderId}}
			</view>

			<view class="goodsContent">
				<view class="goodsImage">
					<image :src="'https://www.2306.tech/CCShop/'+order.orderImage" style="width: 200upx;height: 200upx;" mode=""></image>
				</view>
				<view class="goodsInfo">
					<view class="goodsName">{{order.orderName}}</view>
					<view class="goodsPrice">
						<text>
							单价：<text class="text-price">{{order.orderTotalFee}}</text>
						</text>
						<text class="margin-left">
							数量：{{order.orderCount}}
						</text>
					</view>
					<view class="goodsTotalPrice">总额：<text class="text-price text-red">{{order.orderTotalFee}}</text></view>
				</view>
			</view>
		</view>

		<view class="evaluationView">
			<view class="rateView">
				打分： <uni-rate  :is-fill="false" @change="onChange"/>
			</view>
			<view class="commentView" style="border: 1px solid #808080; border-radius: 30upx;margin-top: 20upx;">
				<textarea @input="input" placeholder="  我们期待您的反馈" confirm-type="done" />
			</view>
			<view class="padding-bottom"></view>
		</view>
		
		<view class="buttonArea">
			<button class="cu-btn bg-green shadow lg" @click="submit" :disabled="disabled">提交评价</button>
		</view>


	</view>
</template>

<script>
	import {
		getOrderShortInfoById
	} from '../../api/orderAPI.js'
	import { createEvaluationByOrderId } from '../../api/evaluationAPI.js'
	import uniRate from '../../components/uni-rate/uni-rate.vue'
	export default {
		components: {
			uniRate
		},
		data() {
			return {
				order: {
					"orderImage": "images/goods/FA0257/FA0257-0.jpg",
					"orderSinglePrice": 18.8,
					"orderTotalFee": 17.76,
					"orderCount": "",
					"orderName": "阜平花山香菇干200g 珍珠菇 蘑菇 菌菇 无根 南北山珍干货 煲汤红烧蒸蛋"
				},
				orderId: '',
				evaluation: {
					evaluationStar: 0,
					evaluationContent:''
				},
				disabled:false
			}
		},
		onLoad(params) {

			let orderId = params.orderId;

			this.orderId = 'G20201216161638568'
			if (orderId) {
				getOrderShortInfoById(orderId).then(resp => {
					this.order = resp
				})
			}

		},
		methods: {
			onChange(e) {
				this.evaluation.evaluationStar = e.value
				console.log("this.evaluation.evaluationStar: ",this.evaluation.evaluationStar);
			},
			submit() {
				console.log("this.evaluation: "+ JSON.stringify(this.evaluation));
				createEvaluationByOrderId(this.orderId,this.evaluation).then(resp => {
					// if('success' == resp.result) {
						this.disabled =true
						
						uni.showToast({
							title:'评价提交成功',
							duration:2000
						})
						
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},2500)
						
					// } else {
					// 	uni.showToast({
					// 		title:'服务器繁忙，请再试一次',
					// 		duration:2000,
					// 		icon:'none'
					// 	})
					// }
				})
				
			},
			input(event) {
				this.evaluation.evaluationContent = event.detail.value
			}
		}
	}
</script>

<style>
	@import url("./evaluation.css");
</style>
